import { Button, message, Form, Input, Space } from "antd";
import { useModel } from "umi";

import useUpdateType from "../../hooks/application/person/useUpdateType";

const EditApplicationTypeForm = ({ item, reloadData }) => {
    const { onCloseGlobalModal } = useModel("global.modal");
    const { submitLoading, updateApplicationType } = useUpdateType();

    const [form] = Form.useForm();

    const onFinish = async (values) => {
        let params = {
            appUuid: item.appUuid,
            appType: item.appType,
            data: values,
        };
        updateApplicationType(params, (res) => {
            if (res) {
                message.success("成功更新应用客户端信息");
                form.resetFields();
                reloadData();
                onCloseGlobalModal();
            }
        });
    };

    return (
        <div style={{ padding: "0 30px 0 30px" }}>
            <Form form={form} onFinish={onFinish} layout="vertical" initialValues={item}>
                <Form.Item label="路由路径" name="appPath">
                    <Input />
                </Form.Item>

                <Form.Item label="代码网址" name="appGiturl">
                    <Input />
                </Form.Item>

                <Form.Item label="Git地址" name="appGitlab">
                    <Input />
                </Form.Item>

                <Form.Item label="客户端描述" name="appDesc">
                    <Input.TextArea />
                </Form.Item>

                <Form.Item style={{ textAlign: "center" }}>
                    <Space>
                        <Button loading={submitLoading} type="primary" htmlType="submit">
                            保存应用客户端信息
                        </Button>
                        <Button loading={submitLoading} htmlType="button" onClick={() => form.resetFields()}>
                            重置
                        </Button>
                    </Space>
                </Form.Item>
            </Form>
        </div>
    );
};

export default EditApplicationTypeForm;
